package hust.rpc.serialize.kryo;

import hust.rpc.serialize.Serializer;

import java.io.IOException;

public class KryoSerializer implements Serializer {
    @Override
    public byte[] serialize(Object obj) {
        try {
            return KryoUtils.serialize(obj);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) {
        T t = null;
        try {
            return (T) KryoUtils.deserialize(bytes);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}
